using System.Collections;
using Anvil.Core;
using Anvil.Core.Commands;

namespace PhoneBook.Core.Commands
{
    /// <summary>
    /// Execute database statement indicated by QueryID 
    /// for a single object, 
    /// returning each attribute in the main context.
    /// </summary>
    /// 
    public class BaseEntry : BaseMapper
    {
        public override bool RequestExecute(IRequestContext context)
        {
            object o = Mapper.QueryForObject(QueryID, context);
            IDictionary result = o as IDictionary;

            if (result!=null)
            {
                ICollection keys = result.Keys;
                foreach (string key in keys)
                {
                    context[key] = result[key];
                }
                AppEntry entry = new AppEntry(result);
                context[ID] = entry;                
            }

            return CONTINUE;
        }
    }
}